package com.yimi.appstore.anim;

import android.text.Layout;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.LinearInterpolator;
import android.view.animation.OvershootInterpolator;
import android.widget.AbsoluteLayout;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;

/** 
 * 类说明：   
 * @author  Terry Lu
 * @date    2012-2-3
 * @version 1.0
 */
public class Add2CartAnimProvider{
	private static final String TAG = Add2CartAnimProvider.class.getSimpleName();
	private ViewGroup mViewGroup;
	
	public Add2CartAnimProvider(final ViewGroup parent) {
		mViewGroup = parent;
	}
	
	public Animation getAnimation(final float fromXDelta, final float toXDelta, final float fromYDelta, 
			final float toYDelta, final View v , int x ,int y ) {
		if (mViewGroup instanceof RelativeLayout) {
			RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
			lp.setMargins(x-50, y, 0, 0);
//			lp.addRule(RelativeLayout.CENTER_IN_PARENT);
			mViewGroup.addView(v, lp);
		}
		
		final ParabolaAnimation animation = new ParabolaAnimation(fromXDelta, toXDelta, fromYDelta, toYDelta);
		animation.setDuration(1000);
		v.setAnimation(animation);
		ParabolaBounceInterpolator i = new ParabolaBounceInterpolator();
		animation.setInterpolator(new AccelerateDecelerateInterpolator());
		
		animation.setAnimationListener(new AnimationListener() {
			
			@Override
			public void onAnimationStart(Animation animation) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onAnimationRepeat(Animation animation) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onAnimationEnd(Animation animation) {
				// TODO Auto-generated method stub
				v.setVisibility(View.GONE);
			}
		});
		return animation;
	}
}
